﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Dao.Intermediarios
{
    public class IPDetalleOC:Intermediario
    {
         public override void save<T>(T entity)
        {
            try 
	        {
                DetalleOrdenCompra oc = entity as DetalleOrdenCompra;
                dao.DetalleOrdenCompras.InsertOnSubmit(oc);		
	        }
	        catch (Exception e)
	        {		
		        throw new Exception("IPRDetallePedido.Save - " + e.Message);
	        }
        }

        public override List<T> getAll<T>()
        {
            return (from oc in dao.OrdenCompras select oc).ToList() as List<T>;
        }

        public override List<T> getByCriterio<T>(string att, string op, string val)
        {
            List<T> listita = dao.ExecuteQuery<DetalleOrdenCompra>("SELECT * FROM [DetalleOrdenCompra] WHERE [DetalleOrdenCompra]." + att + " " + op + " '" + val + "'").ToList() as List<T>;

            return listita;
        }

        public override IList<T> getCriterioById<T>(string att, string op, int val)
        {
            return (from oc in dao.DetalleOrdenCompras where oc.idOC== Convert.ToInt16(val) select oc).ToList() as List<T>;
        }

        public override object getPorId(int id)
        {
            throw new NotImplementedException();
        }

        public override IList<T> getPorCriterio<T>(string name)
        {
            throw new NotImplementedException();
        }

        public override void Update<T>(T entity)
        {
            try
            {

            }
            catch (Exception)
            {
                
                throw;
            }
        }

        public override void Delete(int id)
        {
            try
            {
                var ct = (from oc in dao.OrdenCompras where oc.nroOrdenCompra == id select oc).SingleOrDefault();

                if (ct != null)
                {
                  //  ct.Activo = false;
                    dao.OrdenCompras.DeleteOnSubmit(ct);
                    dao.SubmitChanges();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
    }

    }

